<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>1.DOM节点操作</title>
  <style>
    .container {
      border: 1px solid #ccc;
    }
    .red {
      color: red;
    }
  </style>
</head>
<body>
  <!-- 1.获取节点 -->
  <!-- 2.attribute property -->
  property: 修改对象属性，不会体现到html结构中
  attribute: 修改html属性，会改变html结构
  两这个都会引起DOM重新渲染

  <div id="div1" class="container">
    <p>一段文字1</p>
    <p>一段文字2</p>
    <p>一段文字3</p>
  </div>
  <div id="div2" class="container">
    <img src="http://hbimg.huabanimg.com/3295eee156523d2aac54e36f0ff13b3a7e0d3a221a7c-joGTzz_fw658/format/webp" alt="">
  </div>

  <script>
    // 1.获取DOM节点
    /* const div1 = document.getElementById('div1')
    console.log('div1', div1);

    const divList = document.getElementsByTagName('div') // 集合
    console.log('divList.length', divList.length);
    console.log('divList', divList);

    const containerList = document.getElementsByClassName('container')
    console.log('containerList.length', containerList.length);
    console.log('containerList[1]', containerList[1]);

    const pList = document.querySelectorAll('p')
    console.log('pList', pList); */

    const pList = document.querySelectorAll('p')
    const p1 = pList[0]

    // 2.DOM节点的property
    p1.style.width = '100px'
    console.log(p1.style.width);
    p1.className = 'red'
    console.log(p1.className);
    console.log(p1.nodeName);
    console.log(p1.nodeType); 

    // 2.DOM节点的attribute
    /* p1.setAttribute('data-name', 'webNB')
    console.log(p1.getAttribute('data-name'));
    p1.setAttribute('style', 'font-size: 50px')
    console.log(p1.getAttribute('style')); */






  </script>
  
</body>
</html>